package main

import "fmt"

func main() {
	months := [...]string{
		1:  "January",
		2:  "February",
		3:  "March",
		4:  "April",
		5:  "May",
		6:  "June",
		7:  "July",
		8:  "August",
		9:  "September",
		10: "October",
		11: "November",
		12: "December"}
	Q2 := months[4:7]
	summer := months[6:9]

	fmt.Println(Q2)     // ["April" "May" "June"]
	fmt.Println(summer) // ["June" "July" "August"]

	for _, s := range summer {
		for _, q := range Q2 {
			if s == q {
				fmt.Printf("%s appears in both\n", s)
			}
		}
	}

	fmt.Println(cap(summer)) //容量是从 6到months的最后一个 总共7个

	// fmt.Println(summer[:20]) // panic: out of range

	endlessSummer := summer[:5] // extend a slice (within capacity) 自动扩充
	fmt.Println(endlessSummer)  // "[June July August September October]"

	a := [...]int{0, 1, 2, 3, 4, 5}
	// reverse(a[:])
	// fmt.Println(a)

	reverse(a[:2])
	fmt.Println(a)

	s := []int{1, 2}
	b := []int{1, 2, 3}
	fmt.Println(equal(s, b))
}

//翻转
func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

//相等判断
func equal(x, y []int) bool {
	if len(x) != len(y) {
		return false
	}
	for i := range x {
		if x[i] != y[i] {
			return false
		}
	}
	return true
}
